/**
 * runner
 */
package com.whilefor.runner.modules.runner.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.whilefor.runner.common.config.Global;
import com.whilefor.runner.common.persistence.Page;
import com.whilefor.runner.common.web.BaseController;
import com.whilefor.runner.common.utils.StringUtils;
import com.whilefor.runner.modules.runner.entity.RunnerGoodsOrderPayinfo;
import com.whilefor.runner.modules.runner.service.RunnerGoodsOrderPayinfoService;

/**
 * 商品交割单管理Controller
 * @author lins
 * @version 2016-04
 */
@Controller
@RequestMapping(value = "${adminPath}/runner/runnerGoodsOrderPayinfo")
public class RunnerGoodsOrderPayinfoController extends BaseController {

	@Autowired
	private RunnerGoodsOrderPayinfoService runnerGoodsOrderPayinfoService;
	
	@ModelAttribute
	public RunnerGoodsOrderPayinfo get(@RequestParam(required=false) String id) {
		RunnerGoodsOrderPayinfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = runnerGoodsOrderPayinfoService.get(id);
		}
		if (entity == null){
			entity = new RunnerGoodsOrderPayinfo();
		}
		return entity;
	}
	
	@RequiresPermissions("runner:runnerGoodsOrderPayinfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(RunnerGoodsOrderPayinfo runnerGoodsOrderPayinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<RunnerGoodsOrderPayinfo> page = runnerGoodsOrderPayinfoService.findPage(new Page<RunnerGoodsOrderPayinfo>(request, response), runnerGoodsOrderPayinfo); 
		model.addAttribute("page", page);
		return "modules/runner/runnerGoodsOrderPayinfoList";
	}

	@RequiresPermissions("runner:runnerGoodsOrderPayinfo:view")
	@RequestMapping(value = "form")
	public String form(RunnerGoodsOrderPayinfo runnerGoodsOrderPayinfo, Model model) {
		model.addAttribute("runnerGoodsOrderPayinfo", runnerGoodsOrderPayinfo);
		return "modules/runner/runnerGoodsOrderPayinfoForm";
	}

	@RequiresPermissions("runner:runnerGoodsOrderPayinfo:edit")
	@RequestMapping(value = "save")
	public String save(RunnerGoodsOrderPayinfo runnerGoodsOrderPayinfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, runnerGoodsOrderPayinfo)){
			return form(runnerGoodsOrderPayinfo, model);
		}
		runnerGoodsOrderPayinfoService.save(runnerGoodsOrderPayinfo);
		addMessage(redirectAttributes, "保存商品交割单成功");
		return "redirect:"+Global.getAdminPath()+"/runner/runnerGoodsOrderPayinfo/?repage";
	}
	
	@RequiresPermissions("runner:runnerGoodsOrderPayinfo:edit")
	@RequestMapping(value = "delete")
	public String delete(RunnerGoodsOrderPayinfo runnerGoodsOrderPayinfo, RedirectAttributes redirectAttributes) {
		runnerGoodsOrderPayinfoService.delete(runnerGoodsOrderPayinfo);
		addMessage(redirectAttributes, "删除商品交割单成功");
		return "redirect:"+Global.getAdminPath()+"/runner/runnerGoodsOrderPayinfo/?repage";
	}

}